Vue.prototype.base_url = 'http://wuyicaomeimiao.com/';
import Vue from 'vue' //引入vue
import VueResource from 'vue-resource'//引入vue-resource
import {Header,Swipe,SwipeItem,Lazyload,Button,Switch,Field,Search } from 'mint-ui' //引入mint-ui
import VueRouter from 'vue-router' 
Vue.use(VueRouter)
Vue.use(VueResource)
Vue.use(Lazyload)
Vue.component(Swipe.name,Swipe)
Vue.component(Button.name, Button);
Vue.component(SwipeItem.name,SwipeItem)
Vue.component(Switch.name,Switch)
Vue.component(Field.name,Field)
Vue.component(Search.name,Search)

import Vuex from "vuex" 
Vue.use(Vuex)
//引入vuexvuex是vue配套的公共管理工具，他可以把一些公共的数据，
//保存到vuex中方便整个程序中的任何组件直接获取或修改公共的资源！
var store = new Vuex.Store({
    state:{//相当于data，不建议直接修改state里面的值，不方便以后维护，做好借助与mutations里面的函数修改
        car : JSON.parse(localStorage.getItem('car')||'[]') ,
    },
    mutations:{//相当于methods
        getShoppingNum (state,car){//mutations里面的函数第一个参数值是固定的state
            var key = true
            state.car.some(function(e){
                if(e.id == car.id){
                    e.num += car.num
                    key = false
                }
            })
            if(key){
                state.car.push(car)
            }
            localStorage.setItem('car',JSON.stringify(state.car))
        },
        getShoppingCarNum (state,data){
            state.car[data.id].num = data.num
            localStorage.setItem('car',JSON.stringify(state.car))
            // state.car.some(function(e){
            // })
        },
        removeCar(state,index){
            state.car.splice(index,1)
            localStorage.setItem('car',JSON.stringify(state.car))
        },
        amendSelect(state,data){
            state.car[data.index].select = data.state
            localStorage.setItem('car',JSON.stringify(state.car))
        }
    },
    getters:{//和computed和filter比较像，getters不负责修改数据负责向外提供数据想要修改数据去mutations
        setNum :function(state){
            // console.log(state.car[0].num)
            var c = 0
            state.car.forEach(function(e){
                c += e.num
            })
            return c
        }
    }
})


import VuePreview from 'vue-preview'//缩略图插件
// defalut install
// Vue.use(VuePreview)
// with parameters install

Vue.use(VuePreview, {
    mainClass: 'pswp--minimal--dark',
    barsSize: {top: 0, bottom: 0,display:'none'},
    captionEl: true,//标题
    fullscreenEl: true,//全屏
    shareEl: false,//分享
    bgOpacity: 0.98,
    tapToClose: true,
    tapToToggleControls: false
  })
import 'mint-ui/lib/style.css'//引入mint-ui组件样式
Vue.component(Header.name, Header);//按需引入mint-ui组件的header组件

import app from './app.vue'//引入组件

import './css/index.css'//引入css

import './lib/mui/css/mui.min.css'//引入mui样式
import './lib//mui/css/icons-extra.css'//引入mui字体图标
import router from './router.js'
Vue.filter("time",function(msg,val){
    if(msg){
        msg = typeof msg=="string"?msg.indexOf('T')?msg:msg.split("-").join('/'):msg
        var t = new Date(msg)
        var y = t.getFullYear()
        var m = (t.getMonth()+1)>9?(t.getMonth()+1):("0"+(t.getMonth()+1))
        var d = t.getDate()>9?t.getDate():("0"+t.getDate())
        var h = t.getHours()>9?t.getHours():("0"+t.getHours())
        var min = t.getMinutes()>9?t.getMinutes():("0"+t.getMinutes())
        var s = t.getSeconds()>9?t.getSeconds():("0"+t.getSeconds())
        if(val == 'yyyy-mm-dd'){
            return y +"-"+ m + "-" + d 
        }else{
           return y +"-"+ m + "-" + d +" "+ h +":"+ min + ":" +s
        }
    }
})

var vm = new Vue({
     el:'#app',
     data:{
        
     },
     render:c=>c(app),
     router,
     store,
     methods:{

     }
 })
 
